<?php
 $num_bdd_sql = IsSet ($_POST ["num_bdd_sql"]) ? $_POST ["num_bdd_sql"] : (IsSet ($_GET ["num_bdd_sql"]) ? $_GET ["num_bdd_sql"] : 0) ;
 
 If (File_Exists ("./include/garennes.cfg")) { Include ("./include/garennes.cfg") ; } Else { $installation = 0 ; }
 If (File_Exists ("./include/garennes_bdd.cfg")) { Include ("./include/garennes_bdd.cfg") ; } Else { $bdd [0][0] = 0 ; }
 If ($num_bdd_sql > 0) { $bdd_sql = $bdd [$num_bdd_sql][1] ; }
 If ((!IsSet ($installation)) Or (File_Exists ("./majig"))) { $installation = 0 ; }
 If ((File_Exists ("./verif_install.php")) And ($installation == 0)) { Include ("./verif_install.php") ; }
 Include_Once ("./include/init.php") ;
 $login = var_courante ("login", 0, null) ;
 $identifiant = var_courante ("identifiant", 0, null) ;
 $passe = var_courante ("passe", 0, null) ;
 $sortie = var_courante ("sortie", 0, null) ;
 
 //echo $login."-".$identifiant."-".$passe."-".$sortie."<br>" ;
 //exit;
 // ENT externe
 If (IsSet ($ebranly_identifiant) And IsSet ($ebranly_passe)) { $identifiant = $ebranly_identifiant ; $passe = $ebranly_passe ; }

 If (IsSet ($identifiant) And IsSet ($passe) And !IsSet ($sortie))
  {
   $identifiant = Strip_Tags ($identifiant) ;
   $identifiant = Str_Replace (" ", "", $identifiant) ;
   $identifiant = Str_Replace ("%20", "", $identifiant) ;
   $identifiant = AddSlashes ($identifiant) ;
   
   $passe = Strip_Tags ($passe) ;
   $passe = Str_Replace (" ", "", $passe) ;
   $passe = Str_Replace ("%20", "", $passe) ;
   $passe = AddSlashes ($passe) ;
   $dts = droits ($identifiant, $passe) ;
   If (Is_Array ($dts))
    {
     $droits = $dts [0] ;
     $id_classe = $dts [1] ;
    }
   Else { $droits = $dts ; }
   //echo $droits;exit;
   $code = init_session ($droits, $identifiant, $passe) ;
   $droits = droitsparsession ($code) ;
   If (Empty ($droits)) { Header ("Location: ".$page_premiere."?login=0&sortie=2") ; }
   $delta_millesime = 0 ;
   Session_Start () ;
   $_SESSION ["identifiant"] = $identifiant ;
   $_SESSION ["passe"] = $passe ;
   $_SESSION ["code"] = $code ;
   $_SESSION ["repertoire_config"] = $repertoire_config ;
   $_SESSION ["cahier_textes_id"] = $cahier_textes_id ;
   $_SESSION ["chaine_clef"] = cryptage_sommaire ($identifiant."|".$passe."|", "") ;
   If ($num_bdd_sql > 0)
    {
     $_SESSION ["bdd_sql"] = $bdd [$num_bdd_sql][1] ;
     If (($multi_etablissement == 1) And ($multi_bases == 0)) { $_SESSION ["entete_sql"] = $bdd [$num_bdd_sql][2]."_" ; } Else { $_SESSION ["entete_sql"] = "" ; }
    }
   Else
    {
     $_SESSION ["bdd_sql"] = $sql_base ;
     If (($multi_etablissement == 1) And ($multi_bases == 0)) { $_SESSION ["entete_sql"] = $sql_entete."_" ; } Else { $_SESSION ["entete_sql"] = "" ; }
    }
   $_SESSION ["delta_millesime"] = $delta_millesime ;
   SetCookie ("etablissement_scolaire_garennes", $_SESSION ["bdd_sql"], Time ()+8035200) ; // Validite : 1 mois
   $rcc = change_periode_classes () ;
   $fs = "" ;
   For ($i = 1 ; $i <= $rcc [0][0] ; $i++)
    {
     If (($rcc [$i][1] == 1) Or ($rcc [$i][1] == 2)) { $fs = "&fs=1" ; }
    }
   Switch ($droits)
    {
     Case $aucun_droit         : Header ("Location: ".$page_premiere."?login=1&sortie=2") ; Break ;
     Case $droit_eleve         : Header ("Location: ".$http_eleve."index.php?PHPSESSID=".Session_Id ()) ; Break ;
     Case $droit_cahier_textes : Header ("Location: ".$http_cahier_textes."index.php?PHPSESSID=".Session_Id ()) ; Break ;
     Case $droit_trombinoscope : Header ("Location: ".$http_trombinoscope."index.php?PHPSESSID=".Session_Id ()) ; Break ;
     Case $droit_prof          : Header ("Location: ".$http_profs."index.php?PHPSESSID=".Session_Id ().$fs) ; Break ;
     Case $droit_surveillant   : Header ("Location: ".$http_surveillant."index.php?PHPSESSID=".Session_Id ().$fs) ; Break ;
     Case $droit_cpe           : Header ("Location: ".$http_cpe."index.php?PHPSESSID=".Session_Id ().$fs) ; Break ;
     Case $droit_secretariat   : Header ("Location: ".$http_secre."index.php?PHPSESSID=".Session_Id ().$fs) ; Break ;
     Case $droit_direction     : Header ("Location: ".$http_direc."index.php?PHPSESSID=".Session_Id ().$fs) ; Break ;
     Case $droit_admin         : Header ("Location: ".$http_admin."index.php?PHPSESSID=".Session_Id ().$fs) ; Break ;
     Case $droit_supervision   : Header ("Location: ".$http_supervision."index.php?PHPSESSID=".Session_Id ()) ; Break ;
     Default                   : Header ("Location: ".$page_rien) ; Break ;
    }
   Exit ;
  }
 Else
  {
   Session_Start () ;
   Session_UnSet () ;
   Include ("./images/themes/config.inc") ;
   //$repertoire = $repertoire_racine."images/themes/".$themes [$themes [0][1]][1] ;
   Include ($repertoire_racine."images/themes/".$themes [$themes [0][1]][1]."/config.inc") ;
   If (IsSet ($login) And ($login == 1)) { Include ("./include/login.inc") ; }
   Else
    {
     If (!IsSet ($sortie)) { $sortie = 0 ; }
     Echo entete_page ("","") ;
     Echo "<html><head>" ;
     Echo "<link rel=\"shortcut icon\" href=\"./images/icone.ico\">" ;
     Echo "<script type=\"text/javascript\">" ;
     //Echo "var nav=navigator.userAgent;" ;
     Echo " hauteur=screen.height-35;" ;
     Echo " largeur=screen.width;" ;
     //Echo "if(nav.indexOf('MSIE')==-1){hauteur=580;largeur=780}else{hauteur=580;largeur=780}" ;
     //Echo "var caracteristiques=\"top=0,left=0,height=\"+hauteur+\",width=\"+largeur+\",resizable=1,status=0,scrollbars=1,menubar=0,directories=0,toolbar=0,location=no,copyhistory=0\";" ;
     //Echo "var oSampWin=window.open(\"./index.php?login=1&sortie=".$sortie."\",\"Garennes_parent\",caracteristiques);" ;
     //Echo "var caracteristiques=\"top=0,left=0,height=\"+hauteur+\",width=\"+largeur+\",resizable=1,status=0,scrollbars=1,menubar=0,directories=0,toolbar=0,location=0,copyhistory=0\";" ;
     Echo "var caracteristiques=\"top=0,left=0,height=\"+hauteur+\",width=\"+largeur;" ;
     //Echo "var oSampWin=window.open(\"./index.php?login=1&sortie=".$sortie."\",\"Garennes_parent\",caracteristiques);" ;
     Echo "void window.open(\"./index.php?login=1&sortie=".$sortie."\",\"Garennes_parent\",caracteristiques);" ;
     Echo "</script>" ;
     Echo "</head>" ;
     Echo "<body background=\"./images/fond.png\">" ;
     Echo "<center><img src=\"./images/logo.png\" border=\"0\" hspace=\"0\" vspace=\"0\" align=\"bottom\" alt=\"LOGO.\"><font color=\"#ff0000\" size=\"-1\">v".$version_garennes."</font></center>" ;
     Echo "<div name=\"fenetre\">" ;
     Echo "<table border=\"1\" bgcolor=\"".$theme [0][3]."\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:1px solid ".$theme [0][29].";border-collapse:collapse\">" ;
     Echo "<tr><td>" ;
     Echo "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">" ;
     Echo "<tr><td>&nbsp;</td></tr>" ;
     Echo "<tr><td align=\"center\">&nbsp;Si&nbsp;vous&nbsp;ne&nbsp;voyez&nbsp;que&nbsp;cette&nbsp;fen&ecirc;tre&nbsp;sans&nbsp;avoir&nbsp;le&nbsp;logiciel,&nbsp;</td></tr>" ;
     Echo "<tr><td align=\"center\">&nbsp;c'est&nbsp;que&nbsp;vous&nbsp;n'avez&nbsp;pas&nbsp;activ&eacute;&nbsp;certainement&nbsp;les&nbsp;<b>POP-UP</b>.&nbsp;<br>&nbsp;</td></tr>" ;
     Echo "<tr><td align=\"center\">&nbsp;Activez&nbsp;les&nbsp;<br>&nbsp;<b>POP-UP</b>,&nbsp;les&nbsp;<a href=\"./info_cookies.html\" target=\"_blank\"><b>Cookies</b></a>&nbsp;et&nbsp;le&nbsp;<b>JavaScript</b>&nbsp;<br>&nbsp;de&nbsp;votre&nbsp;navigateur&nbsp;internet&nbsp;</td></tr>" ;
     Echo "<tr><td align=\"center\">&nbsp;avant&nbsp;de&nbsp;relancer&nbsp;une connexion&nbsp;&agrave;&nbsp;Garennes.&nbsp;</td></tr>" ;
     Echo "<tr><td>&nbsp;</td></tr>" ;
     Echo "</table>" ;
     Echo "</td></tr></table></div>" ;
     Echo "</body></html>" ;
    }
  }
?>